//
// Created by PC on 2024/4/19.
// 判断链表是否有环
// https://blog.csdn.net/u010983881/article/details/78896293
//


#include <iostream>
#include "linkedListUtil.h"

using namespace std;

bool isCircle(Node *head)
{
    Node *fast=head;
    Node *slow=head;
    while(fast && fast->next)
    {
        fast=fast->next->next;
        slow = slow->next;
        if (fast->v == slow->v)
            return true;
    }
    return false;
}

int main()
{
    vector<int> l{0,1,2,3,4,5};
    Node *head = build(l);
    Node *cur=head->next;
    Node *two=nullptr;
    // 修改成环链表 5->2
    for (int i = 0; i < l.size(); ++i)
    {
        if(cur->v==2)
            two=cur;
        if(i==l.size()-1)
            cur->next=two;
        cur=cur->next;
    }
    cout<<isCircle(head);
    return 0;
}